import request from '@/utils/request'

export function getUserList (params) {
  return request(
    {
      method: 'GET',
      url: '/users',
      params
    }
  )
}

export function userStateChanged (id, state) {
  return request(
    {
      method: 'PUT',
      url: `/users/${id}/state/${state}`
    }
  )
}

export function addUser (data) {
  return request(
    {
      method: 'POST',
      url: '/users',
      data
    }
  )
}

export function showEditDialog (id) {
  return request(
    {
      url: `/users/${id}`,
      method: 'GET'
    }
  )
}

export function editUserInfo (editForm) {
  return request(
    {
      url: `/users/${editForm.id}`,
      method: 'PUT',
      data: {
        email: editForm.email,
        mobile: editForm.mobile
      }
    }
  )
}

export function removeUserById (id) {
  return request(
    {
      url: `/users/${id}`,
      method: 'DELETE'
    }
  )
}

export function seyRole () {
  return request(
    {
      url: '/roles'
    }
  )
}

export function saveRoleInfo (id, data) {
  return request(
    {
      url: `users/${id}/role`,
      method: 'PUT',
      data: {
        rid: data
      }
    }
  )
}
